package com.wang.web_socket;

import com.alibaba.fastjson.JSONObject;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
import org.java_websocket.handshake.ServerHandshake;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;

public class WebSocketTest {
    public static void main(String[] args) throws URISyntaxException, InterruptedException {
//        URI uri = new URI("wss://prestg6-seller.advai.cn/chat/ws");
        URI uri = new URI("ws://localhost:9010/ws");
        HashMap<String, String> map = new HashMap<>();
        map.put("Sec-WebSocket-Protocol", "eyJhbGciOiJSUzI1NiJ9.eyJhY2NvdW50SWQiOiJVNUREQ0M1MzY5QkQxMTYwMDAxQURENjk4IiwicGhvbmUiOiIiLCJlbWFpbCI6ImN1aXBpbmcubWFAYWR2YW5jZS5haSIsImV4cCI6MTY0NTE1NDg0MiwiaWF0IjoxNjQ0ODk1NjQyfQ.UISapOn46dMGbFqSe7V6R42yZwEpf3uTEGJj5Ww5n54Xs69UFEruSIij9WIy1Rz_Fl-V_ddnIX2AnkoGbYAe3KcxP57lsTfQIoYkoUR6c3H6TkG1NrGYE0f3CTnG12UGWL7YouiXpB6hg8AAs6iKO3OAKg19R4_tRLu-1S45zfNy7sGiCRCH7UZQIp9FLtV8ieKmdw7yMteGwPvwjZ_qwArUZJsRIWrSWTNSDFzTQf3sJ8clpV9It1xAgvwkVg7bxDM_8xV_kclFs3HChlzndTlQWUPzE2ChmxgI2XV_9EnPDqcqYApAV-nG3EAy9cLLpcnV00H9cmSCs8c5rT0HPQ");
//        map.put("Sec-WebSocket-Protocol", "asdasd");
        map.put("Origin", "localhost");
        map.put("Host", "http://localhost:9010");
        WebSocketClient client = new WebSocketClient(uri, map) {

            @Override
            public void onOpen(ServerHandshake serverHandshake) {
                System.out.println("opOpen");
            }

            @Override
            public void onMessage(String s) {
                System.out.println("onMessage");

            }

            @Override
            public void onClose(int i, String s, boolean b) {
                System.out.println("onClose:" + s);
            }

            @Override
            public void onError(Exception e) {
                System.out.println("onError");
                e.printStackTrace();
            }
        };
        client.connect();
        System.out.println("end");

    }
}
